package br.com.lucasddaniel.inbuzios.activities;

import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import br.com.lucasddaniel.inbuzios.Controller;
import br.com.lucasddaniel.inbuzios.R;
import br.com.lucasddaniel.inbuzios.adapter.PacotesRelatorioAdapter;
import br.com.lucasddaniel.inbuzios.bean.PacoteArquivoBean;
import br.com.lucasddaniel.inbuzios.bean.PasseioBean;
import br.com.lucasddaniel.inbuzios.dao.ExcessaoBanco;

import com.devsmart.android.ui.HorizontalListView;

public class RelatorioPacotesActivity extends Activity {

//    private ListView lvPacotes;
    private HorizontalListView lvPacotes;
    private Integer idPasseio;
    private PacotesRelatorioAdapter pacoteAdapter;
    private List<PacoteArquivoBean> listPacotes;
	private final Handler mHandler = new Handler();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_relatorio_pacote);

        idPasseio = getIntent().getExtras().getInt("idPasseio");
        PasseioBean pb = new PasseioBean();
        pb.setId(idPasseio);
        try {
            listPacotes = Controller.getInstance().buscarPacotes(pb, getApplicationContext());
        } catch (ExcessaoBanco e) {
            e.printStackTrace();
        }
        initializeComponents();
    }

	@Override
	protected void onResume() {
		super.onResume();
		mHandler.post(new Runnable() {
			public void run() {
				AlertDialog dlg = new AlertDialog.Builder(RelatorioPacotesActivity.this).setTitle("Informação").setMessage("Um clique rápido em qualquer pacote acessa os dados do passeio para alterar.").create();
				dlg.show();
			}
		});
	}
	
    private void initializeComponents() {
    	lvPacotes = (HorizontalListView) findViewById(R.id_activity_listar_pacotes.listview);
//        lvPacotes = (ListView) findViewById(R.id_activity_listar_pacotes.listview);
        pacoteAdapter = new PacotesRelatorioAdapter(getApplicationContext(), R.layout.row_pacotes_relatorio, listPacotes);
        lvPacotes.setAdapter(pacoteAdapter);
        
        lvPacotes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				Intent it = new Intent(RelatorioPacotesActivity.this, GeracaoImpressaoPasseioActivity.class);
				it.putExtra("idPasseio", pacoteAdapter.getItem(position).getIdPasseio());
				startActivity(it);
			}
		});
    }
}
